package org.trinity.netdisk.mapper.handler;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.trinity.netdisk.enums.ShareDays;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ShareDaysEnumTypeHandler extends BaseTypeHandler<ShareDays> {

    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, ShareDays shareDays, JdbcType jdbcType) throws SQLException {
        preparedStatement.setInt(i,shareDays.getCode());
    }

    @Override
    public ShareDays getNullableResult(ResultSet resultSet, String s) throws SQLException {
        return ShareDays.integerToShareDays(resultSet.getInt(s));
    }

    @Override
    public ShareDays getNullableResult(ResultSet resultSet, int i) throws SQLException {
        return ShareDays.integerToShareDays(i);
    }

    @Override
    public ShareDays getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        return ShareDays.integerToShareDays(callableStatement.getInt(i));
    }
}
